<template>
  <div class="container">
    <el-dialog
    class="table"
      title="新增目录"
      :visible="dialogVisible"
      @close="closeFn"
      @open="getList"
    >
      <el-form :model="form" :rules="rules">
        <el-form-item label-width="100px" label="所属学科">
          <el-select
            placeholder="请选择"
            v-model="form.subjectID"
          >
            <el-option
             v-for="item in tableDate"
            :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
         <el-form-item label-width="100px" label="目录名称">
          <el-input v-model="form.directoryName" ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeFn">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { simple } from '@/api/hmmm/subjects.js'
import { add } from '@/api/hmmm/directorys.js'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      form: {
        directoryName: '',
        subjectID: ''
      },
      tableDate: [],
      rules: {}
    }
  },
  methods: {
    async getList () {
      const { data } = await simple()
      this.tableDate = data
    },
    closeFn () {
      this.form = {
        directoryName: '',
        subjectID: ''
      }
      this.$emit('update:dialogVisible', false)
    },
    async submit () {
      const res = await add(this.form)
      console.log(res)
      this.$message.success('上传成功')
      this.closeFn()
      this.$emit('reflesh')
    }
  }
}
</script>

<style scoped lang="less">

</style>
